#ifndef REGISTERWIDGET_H
#define REGISTERWIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QLabel>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QGroupBox>
#include <QScrollArea>
#include <QRegularExpressionValidator>
#include "authservice.h"

class RegisterWidget : public QWidget
{
    Q_OBJECT

public:
    explicit RegisterWidget(AuthService *authService, QWidget *parent = nullptr);
    virtual ~RegisterWidget();

signals:
    void registerSucceeded();
    void switchToLogin();

private slots:
    void onRegisterClicked();
    void onBackToLoginClicked();
    void onRegisterSucceeded();
    void onRegisterFailed(const QString &error);
    void onShowPasswordToggled(bool show);
    void onPasswordChanged();
    void onConfirmPasswordChanged();
    void onUsernameChanged();
    void onEmailChanged();

private:
    void setupUI();
    QWidget* createInputField(const QString &icon, const QString &label, const QString &placeholder, QLineEdit *&lineEdit, QLabel *&hintLabel);
    void setUIEnabled(bool enabled);
    void clearForm();
    void applyStyles();
    bool validateForm();
    bool isValidEmail(const QString &email);
    bool isValidPassword(const QString &password);
    bool isValidUsername(const QString &username);
    void updatePasswordStrength(const QString &password);

    AuthService *m_authService;

    // UI组件
    QVBoxLayout *m_mainLayout;
    QGroupBox *m_registerGroup;
    QFormLayout *m_formLayout;
    
    QLineEdit *m_usernameEdit;
    QLineEdit *m_emailEdit;
    QLineEdit *m_passwordEdit;
    QLineEdit *m_confirmPasswordEdit;
    QCheckBox *m_showPasswordCheck;
    QCheckBox *m_agreeTermsCheck;
    QPushButton *m_registerButton;
    QPushButton *m_backToLoginButton;
    QLabel *m_statusLabel;
    QProgressBar *m_progressBar;
    QLabel *m_titleLabel;
    QLabel *m_logoLabel;
    
    // 验证提示标签
    QLabel *m_usernameHintLabel;
    QLabel *m_emailHintLabel;
    QLabel *m_passwordHintLabel;
    QLabel *m_confirmPasswordHintLabel;
    QLabel *m_passwordStrengthLabel;

    // 样式
    QString m_primaryColor;
    QString m_secondaryColor;
    QString m_backgroundColor;
    QString m_textColor;
    QString m_errorColor;
    QString m_successColor;
    QString m_warningColor;
};

#endif // REGISTERWIDGET_H
